package cn.com.infohold.smartcity.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.List;

import cn.com.infohold.smartcity.R;
import cn.com.infohold.smartcity.activity.Chengbaofang.ChengBaoFangDetail_Activity;
import cn.com.infohold.smartcity.api.bean.ChengBaoFangBean;
import cn.com.infohold.smartcity.parent.ParentActivity;

/**
 * Created by Monsoon on 2017/11/3.
 */
public class Chengbaofang_Adapter extends RecyclerView.Adapter<Chengbaofang_Adapter.mViewHolder>{

    private Context context;
    private List<ChengBaoFangBean> mList;

    public Chengbaofang_Adapter(Context context, List<ChengBaoFangBean> mList) {
        this.context = context;
        this.mList = mList;
    }

    @Override
    public mViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mViewHolder viewHolder = new mViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_chengbaofang, parent, false));
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(mViewHolder holder, int position) {

        ChengBaoFangBean bean = mList.get(position);
        holder.tv_code.setText(bean.getCode());
        holder.tv_name.setText(bean.getName());
        holder.tv_cardid.setText(bean.getCardid());
        holder.tv_birth.setText(bean.getBirth());
        holder.tv_tel.setText(bean.getTel());

        holder.ll_item.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context,ChengBaoFangDetail_Activity.class);
                Bundle bundle = new Bundle();
                bundle.putSerializable("cb_detail",bean);
                intent.putExtra("cb_bundle",bundle);
                context.startActivity(intent);
                ((ParentActivity)context).overridePendingTransitionFade();
            }
        });
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    class mViewHolder extends RecyclerView.ViewHolder{
        LinearLayout ll_item;
        TextView tv_code;
        TextView tv_name;
        TextView tv_cardid;
        TextView tv_birth;
        TextView tv_tel;

        public mViewHolder(View itemView) {
            super(itemView);
            ll_item = (LinearLayout) itemView.findViewById(R.id.ll_item);
            tv_code = (TextView) itemView.findViewById(R.id.tv_code);
            tv_name = (TextView) itemView.findViewById(R.id.tv_name);
            tv_cardid = (TextView) itemView.findViewById(R.id.tv_cardid);
            tv_birth = (TextView) itemView.findViewById(R.id.tv_birth);
            tv_tel = (TextView) itemView.findViewById(R.id.tv_tel);
        }
    }
}
